<template>
  <!-- 查询预约 -->
  <div>
    <TopFilter
      :list="topFilterList"
      :cols="3"
      labelWidth="80"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      height="auto"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    ></FilterTable>
      <!-- selectionType="single" -->
      <!-- :onRowSelectChange="selectChangeHandle" -->
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button @click="closeDialog">返 回</el-button>
      <el-button @click="saveDialog" type="primary">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { getEmpInfo, queryPotentialById } from '@/api/potenCus/customer/driveManagement';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'checkInfo',
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createTopFilters(),
      fetchParams: {},
      visible: false,
      dialogTitle: '',
      fetchApi: getEmpInfo,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      conf: { search: '' },
      selectedRow: null,
      length: ''
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      if (this.type === 'edit' || this.type === 'show') {
        // 更新接口需要的记录 ID
        this.recordId = this.rowData.basedataId;
        this.formList.forEach(x => {
          x.initialValue = this.rowData[x.fieldName];
        });
      }
    },
    // selectChangeHandle(rows) {
    //   if (!rows.length) return;
    //   this.selectedRow = rows[0];
    // },
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          labelWidth: '0',
          render: () =>{
            return (<div>{`当前待处理试驾/乘预约${length}人`}</div>)
          }
        },
        {
          type: 'INPUT',
          label: '客户手机号',
          fieldName: 'potentialCustomerPhone',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'potentialCustomerName',
          placeholder: '请输入'
        },
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 110,
          fixed: 'right',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.startDrive(props.row)}>
                  开始试驾/乘
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '预约日期',
          dataIndex: '11',
          sorter: true,
          width: 150,
          align: 'center',
          // render: props =>{
          //   return <span>{ formatDates(props.row.driveSAt) } </span>
          // }
        },
        {
          title: '预约时段',
          dataIndex: '22',
          sorter: true,
          width: 150,
          align: 'center',
          // render: props =>{
          //   return <span>{ formatDates(props.row.driveSAt) } </span>
          // }
        },
        {
          title: '意向类型',
          dataIndex: 'type',
          sorter: true,
          width: 150,
          align: 'center',
          // render: props =>{
          //   return <span>{ formatDates(props.row.driveSAt) } </span>
          // }
        },
        {
          title: '客户名称',
          dataIndex: 'potentialCustomerName',
          filterType: 'input'
        },
        {
          title: '客户手机号',
          dataIndex: 'potentialCustomerPhone',
          filterType: 'input'
        },
        {
          title: '试驾人姓名',
          dataIndex: 'customerName',
          filterType: 'input'
        },
        {
          title: '试驾人手机号',
          dataIndex: 'mobile',
          filterType: 'input'
        },
        {
          title: '展厅顾问',
          dataIndex: 'employeeName',
          filterType: 'input'
        },
        {
          title: '试驾路线',
          dataIndex: 'wayName',
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'brizhu',
          filterType: 'input'
        },
      ];
    },
    startDrive(row){
      console.log('预约试驾')
    },
    saveDialog() {
      this.closeDialog(this.selectedRow);
    },
    closeDialog(data) {
      this.$emit('close', false, data);
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}`;
      this.visible = true;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  }
};
</script>

<style lang="less" scoped>
</style>
